﻿
namespace Patterns4Net.ArchitectureExplorer.ViewModels.Graph
{
    using Caliburn.Micro;
    using Patterns4Net.ArchitectureExplorer.Diagram;
    using Patterns4Net.ArchitectureExplorer.ViewModels.Messages;

    public class VertexViewModel
    {
        private readonly IEventAggregator eventAggregator;

        public VertexViewModel(DiagramElement diagramElement, IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;
            this.DiagramElement = diagramElement;
        }

        public DiagramElement DiagramElement { get; private set; }

        /// <summary>
        /// Returns an object that will be used for rendering of inner content of the vertex.
        /// </summary>
        /// <remarks><para> 
        /// Border and click/double click functionality is same for all VertexViewModels, 
        /// but inner content may be changed from <see cref="DiagramElement"/> by overriding this property.
        /// </para></remarks>
        public virtual object ContentViewModel
        {
            get { return this.DiagramElement; }
        }

        public string Type
        {
            get { return this.GetType().Name; }
        }

        public void Select()
        {
            this.eventAggregator.Publish(new SelectDiagramElementMessage(this.DiagramElement));
        }

        public void ZoomIn()
        {
            this.eventAggregator.Publish(new ZoomToDiagramElementMessage(this.DiagramElement));
        }

        public override string ToString()
        {
            return this.DiagramElement.Name;
        }
    }
}
